// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   PayForUtil.java

package com.ronglian.register_mini_program.util.WeiXin;

import java.net.*;
import java.text.SimpleDateFormat;
import java.util.*;

// Referenced classes of package com.calc.mrqbpro.util.WeiXin:
//            MD5Util

public class PayForUtil {

    public PayForUtil() {
    }

    public static boolean isTenpaySign(String characterEncoding, SortedMap packageParams, String API_KEY) {
        StringBuffer sb = new StringBuffer();
        Set es = packageParams.entrySet();
        Iterator it = es.iterator();
        do {
            if (!it.hasNext())
                break;
            java.util.Map.Entry entry = (java.util.Map.Entry) it.next();
            String k = (String) entry.getKey();
            String v = (String) entry.getValue();
            if (!"sign".equals(k) && null != v && !"".equals(v))
                sb.append((new StringBuilder()).append(k).append("=").append(v).append("&").toString());
        } while (true);
        sb.append((new StringBuilder()).append("key=").append(API_KEY).toString());
        String mysign = MD5Util.MD5Encode(sb.toString(), characterEncoding).toLowerCase();
        String tenpaySign = ((String) packageParams.get("sign")).toLowerCase();
        return tenpaySign.equals(mysign);
    }

    public static String createSign(String characterEncoding, SortedMap packageParams, String API_KEY) {
        StringBuffer sb = new StringBuffer();
        Set es = packageParams.entrySet();
        Iterator it = es.iterator();
        do {
            if (!it.hasNext())
                break;
            java.util.Map.Entry entry = (java.util.Map.Entry) it.next();
            String k = (String) entry.getKey();
            String v = (String) entry.getValue();
            if (null != v && !"".equals(v) && !"sign".equals(k) && !"key".equals(k))
                sb.append((new StringBuilder()).append(k).append("=").append(v).append("&").toString());
        } while (true);
        sb.append((new StringBuilder()).append("key=").append(API_KEY).toString());
        String sign = MD5Util.MD5Encode(sb.toString(), characterEncoding).toUpperCase();
        return sign;
    }

    public static String getRequestXml(SortedMap parameters) {
        StringBuffer sb = new StringBuffer();
        sb.append("<xml>");
        Set es = parameters.entrySet();
        for (Iterator it = es.iterator(); it.hasNext(); ) {
            java.util.Map.Entry entry = (java.util.Map.Entry) it.next();
            String k = (String) entry.getKey();
            String v = (String) entry.getValue();
            if ("attach".equalsIgnoreCase(k) || "body".equalsIgnoreCase(k) || "sign".equalsIgnoreCase(k))
                sb.append((new StringBuilder()).append("<").append(k).append("><![CDATA[").append(v).append("]]></").append(k).append(">").toString());
            else
                sb.append((new StringBuilder()).append("<").append(k).append(">").append(v).append("</").append(k).append(">").toString());
        }

        sb.append("</xml>");
        return sb.toString();
    }

    public static int buildRandom(int length) {
        int num = 1;
        double random = Math.random();
        if (random < 0.10000000000000001D)
            random += 0.10000000000000001D;
        for (int i = 0; i < length; i++)
            num *= 10;

        return (int) (random * (double) num);
    }

    public static String getCurrTime() {
        Date now = new Date();
        SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String s = outFormat.format(now);
        return s;
    }

    public static String localIp() {
        String ip = null;
        try {
            for (Enumeration allNetInterfaces = NetworkInterface.getNetworkInterfaces(); allNetInterfaces.hasMoreElements(); ) {
                NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
                List InterfaceAddress = netInterface.getInterfaceAddresses();
                Iterator iterator = InterfaceAddress.iterator();
                while (iterator.hasNext()) {
                    InterfaceAddress add = (InterfaceAddress) iterator.next();
                    InetAddress Ip = add.getAddress();
                    if (Ip != null && (Ip instanceof Inet4Address))
                        ip = Ip.getHostAddress();
                }
            }

        } catch (SocketException socketexception) {
        }
        return ip;
    }
}
